package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.First;
import live.jialing.core.beanvalidator.Second;
import live.jialing.core.domain.Idable;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 家庭关系：家长 - 孩子 - 关系
 * <br>
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "base_family")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Family.class)
public class Family implements Idable<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 关系：爸爸、妈妈、奶奶、爷爷、亲属...
     */
    @NotBlank(message = "关系不能为空", groups = {First.class, Second.class})
    private String title;

    /**
     * 家长
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "parent_id", updatable = false)
    @NotNull(message = "家长不能为空", groups = {First.class, Second.class})
    private Parent parent;

    /**
     * 孩子
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "child_id", updatable = false)
    @NotNull(message = "孩子不能为空", groups = {First.class, Second.class})
    private Child child;
}
